home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / manifest_string.e < prev    next >
Text File  |  1998-12-22  |  8KB  |  389 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class MANIFEST_STRING
  17.    --
  18.    -- When using Manifest Constant STRING.
  19.    --   
  20.    
  21. inherit EXPRESSION;
  22.    
  23. creation {EIFFEL_PARSER} make
  24.  
  25. feature 
  26.    
  27.    start_position: POSITION;
  28.      -- Of the first character '%"'.
  29.    
  30.    to_string: STRING;
  31.      -- Eiffel contents of the string.
  32.    
  33. feature {NONE}
  34.    
  35.    break: ARRAY[INTEGER]; 
  36.      -- If not Void, places in `to_string' where extended notation (with
  37.      -- line(s) break) is used. The corresponding character in to string 
  38.      -- is put on next line.
  39.    
  40.    ascii: ARRAY[INTEGER];
  41.      -- If not Void, places in `to_string' where character are to be 
  42.      -- printed using asci code notation. 
  43.    
  44.    percent: ARRAY[INTEGER];
  45.      -- If not Void, places in `to_string' where character are to be 
  46.      -- printed using percent. 
  47.          
  48. feature {MANIFEST_STRING,MANIFEST_STRING_POOL}
  49.    
  50.    mangling: STRING;
  51.      -- When runnable. Name to be used for the corresponding C 
  52.      -- global variable or for the JVM corresponding field.
  53.  
  54. feature
  55.    
  56.    is_manifest_string: BOOLEAN is true;
  57.  
  58.    is_writable: BOOLEAN is false;
  59.  
  60.    is_current: BOOLEAN is false;
  61.  
  62.    is_static: BOOLEAN is false;     
  63.  
  64.    is_void: BOOLEAN is false;
  65.  
  66.    is_result: BOOLEAN is false;
  67.  
  68.    use_current: BOOLEAN is false;     
  69.  
  70.    is_pre_computable: BOOLEAN is true;
  71.  
  72.    c_simple: BOOLEAN is true;
  73.  
  74.    can_be_dropped: BOOLEAN is true;
  75.  
  76. feature {NONE}
  77.    
  78.    make(sp: like start_position) is
  79.       require
  80.      sp /= Void
  81.       do
  82.      start_position := sp;
  83.      !!to_string.make(0);
  84.       ensure
  85.      start_position = sp
  86.       end;
  87.  
  88. feature 
  89.  
  90.    result_type: TYPE_STRING is
  91.       do
  92.      Result := type_string;
  93.       end;
  94.    
  95.    static_value: INTEGER is
  96.       do
  97.       end;
  98.  
  99.    isa_dca_inline_argument: INTEGER is
  100.       do
  101.       end;
  102.  
  103.    dca_inline_argument(formal_arg_type: TYPE) is
  104.       do
  105.       end;
  106.  
  107.    mapping_c_target(target_type: TYPE) is
  108.       do
  109.      cpp.put_string(mangling);
  110.       end;
  111.  
  112.    frozen mapping_c_arg(formal_arg_type: TYPE) is
  113.       do
  114.      compile_to_c;
  115.       end;
  116.  
  117.    collect_c_tmp is
  118.       do
  119.       end;
  120.  
  121.    compile_to_c is
  122.       do
  123.      cpp.put_character('(');
  124.      cpp.put_string(fz_cast_t0_star);
  125.      cpp.put_string(mangling);
  126.      cpp.put_character(')');
  127.       end;
  128.    
  129.    c_declare_for_old is
  130.       do 
  131.       end;
  132.       
  133.    compile_to_c_old is 
  134.       do 
  135.       end;
  136.  
  137.    compile_to_jvm_old is 
  138.       do 
  139.       end;
  140.  
  141.    afd_check is
  142.       do 
  143.       end;
  144.  
  145.    count: INTEGER is
  146.       do
  147.      Result := to_string.count;
  148.       end;
  149.        
  150.    compile_target_to_jvm, compile_to_jvm is
  151.       local
  152.      idx: INTEGER;
  153.       do
  154.      idx := fieldref_idx;
  155.      code_attribute.opcode_getstatic(idx,1);
  156.       end;
  157.    
  158.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  159.       do
  160.       end;
  161.    
  162.    jvm_branch_if_false: INTEGER is
  163.       do
  164.       end;
  165.  
  166.    jvm_branch_if_true: INTEGER is
  167.       do
  168.       end;
  169.    
  170.    compile_to_jvm_into(dest: TYPE): INTEGER is
  171.       do
  172.      Result := 1;
  173.      compile_to_jvm;
  174.       end;
  175.  
  176.    to_runnable(ct: TYPE): MANIFEST_STRING is
  177.       do
  178.      if mangling = Void then
  179.         mangling := manifest_string_pool.register(Current);
  180.      end;
  181.      Result := Current;
  182.       end;
  183.    
  184.    precedence: INTEGER is
  185.       do
  186.      Result := atomic_precedence;
  187.       end;
  188.    
  189.    bracketed_pretty_print, pretty_print is
  190.       local
  191.      i, column: INTEGER;
  192.       do
  193.      from  
  194.         column := fmt.column;
  195.         fmt.put_character('%"');
  196.         i := 1;
  197.      until
  198.         i > to_string.count
  199.      loop
  200.         if is_on_next_line(i) then
  201.            fmt.put_string("%%%N");
  202.            from  
  203.            until
  204.           column = fmt.column
  205.            loop
  206.           fmt.put_character(' ');
  207.            end;
  208.            fmt.put_character('%%');
  209.         end;
  210.         pretty_print_character(i);
  211.         i := i + 1;
  212.      end;     
  213.      fmt.put_character('%"');
  214.       end;
  215.  
  216.    print_as_target is
  217.       do
  218.      fmt.put_character('(');
  219.      pretty_print;
  220.      fmt.put_character(')');
  221.      fmt.put_character('.');
  222.       end;
  223.  
  224.    short is
  225.       local
  226.      i: INTEGER;
  227.       do
  228.      short_print.hook_or("open_ms","%"");
  229.      from  
  230.         i := 1;
  231.      until
  232.         i > to_string.count
  233.      loop
  234.         short_character(i);
  235.         i := i + 1;
  236.      end;     
  237.      short_print.hook_or("close_ms","%"");
  238.       end;
  239.  
  240.    short_target is
  241.       do
  242.      bracketed_short;
  243.      short_print.a_dot;
  244.       end;
  245.    
  246. feature {EIFFEL_PARSER}
  247.    
  248.    add(ch: CHARACTER) is
  249.      -- Append `ch' to manifest string setting
  250.      -- ordinary printing mode.
  251.       do
  252.      to_string.extend(ch);
  253.       end;
  254.  
  255.    add_ascii(ch: CHARACTER) is
  256.      -- Append `ch' to manifest string setting
  257.      -- `ascii'  printing mode.
  258.       do
  259.      to_string.extend(ch);
  260.      if ascii = Void then
  261.         ascii := <<to_string.count>>;
  262.      else
  263.         ascii.add_last(to_string.count);
  264.      end;
  265.       end;
  266.  
  267.    add_percent(ch: CHARACTER) is
  268.      -- Append `ch' to manifest string setting
  269.      -- `percent'  printing mode.
  270.       do
  271.      to_string.extend(ch);
  272.      if percent = Void then
  273.         percent := <<to_string.count>>;
  274.      else
  275.         percent.add_last(to_string.count);
  276.      end;
  277.       end;
  278.  
  279.    break_line is
  280.      -- Next character will be a `break'.
  281.       do
  282.      if break = Void then
  283.         break := <<to_string.count + 1>>;
  284.      else
  285.         break.add_last(to_string.count + 1);
  286.      end;
  287.       end;
  288.    
  289. feature {NONE}   
  290.    
  291.    pretty_print_character(i: INTEGER) is
  292.       require
  293.      1 <= i;
  294.      i <= count;
  295.       local
  296.      val: INTEGER;
  297.       do
  298.      if percent /= Void and then percent.fast_has(i) then
  299.         tmp_string.clear;
  300.         character_coding(to_string.item(i),tmp_string);
  301.         fmt.put_string(tmp_string);
  302.      elseif ascii /= Void and then ascii.fast_has(i) then
  303.         val := to_string.item(i).code;
  304.         fmt.put_string("%%/");
  305.         fmt.put_integer(val);
  306.         fmt.put_string(us_slash);
  307.      else
  308.         fmt.put_character(to_string.item(i));
  309.      end;
  310.       end;
  311.  
  312.    short_character(i: INTEGER) is
  313.       require
  314.      1 <= i;
  315.      i <= count;
  316.       local
  317.      val: INTEGER;
  318.      second_slash: BOOLEAN;
  319.      c: CHARACTER;
  320.       do
  321.      tmp_string.clear;
  322.      if percent /= Void and then percent.fast_has(i) then
  323.         character_coding(to_string.item(i),tmp_string);
  324.      elseif ascii /= Void and then ascii.fast_has(i) then
  325.         val := to_string.item(i).code;
  326.         tmp_string.append("%%/");
  327.         val.append_in(tmp_string);
  328.         tmp_string.append(us_slash);
  329.      end;
  330.      if tmp_string.count = 0 then
  331.         short_print.a_character(to_string.item(i));
  332.      else
  333.         from
  334.            val := 1;
  335.         until
  336.            val > tmp_string.count
  337.         loop
  338.            c := tmp_string.item(val);
  339.            if c = '%%' then
  340.           short_print.hook_or("Prcnt_ms","%%");
  341.            elseif c = '/' then
  342.           short_print.hook_or("Slash_ms",us_slash);
  343.            else
  344.           short_print.a_character(c);
  345.            end;
  346.            val := val + 1;
  347.         end;
  348.      end;
  349.       end;
  350.    
  351.    is_on_next_line(i: INTEGER): BOOLEAN is 
  352.       require
  353.      1 <= i;
  354.      i <= count;
  355.       do
  356.      if break /= Void then
  357.         Result := break.fast_has(i);
  358.      end;
  359.       end;
  360.    
  361. feature {NONE}
  362.    
  363.    tmp_string: STRING is
  364.       once
  365.      !!Result.make(8);
  366.       end;
  367.  
  368. feature {CREATION_CALL,EXPRESSION_WITH_COMMENT}
  369.       
  370.    jvm_assign is
  371.       do
  372.       end;
  373.  
  374. feature {MANIFEST_STRING_POOL}
  375.  
  376.    fieldref_idx: INTEGER is
  377.       do
  378.      Result := constant_pool.idx_fieldref_for_manifest_string(mangling);
  379.       end;
  380.  
  381. invariant
  382.    
  383.    start_position /= Void;
  384.  
  385.    to_string /= Void;
  386.  
  387. end -- MANIFEST_STRING
  388.  
  389.